package com.tonysong.ssm.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tonysong.ssm.mapper.UserMapper;
import com.tonysong.ssm.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/9/19
 * @Version 1.0
 **/
@Service
//@Scope("prototype")
public class UserServiceImpl  implements UserService{
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageInfo<User> getPageInfo(Integer offset, Integer pageSize) {
        PageHelper.startPage(offset,pageSize);
        return new PageInfo<User>(this.userMapper.getAllUsers());
    }

    @Override
    public List<User> getAllUsers() {
        return this.userMapper.getAllUsers();
    }

    @Override
    public User findById(Integer id) {
        return this.userMapper.findById(id);
    }

    @Override
    public int save(User user) {
        System.out.println("--------------------------------user:"+user);
        if(user.getId() == null || user.getId()==0)
            return this.userMapper.addUser(user);
        return this.userMapper.updateUser(user);
    }


    @Override
    public boolean batch_delete(String ids) {
        String[] arr = ids.split(",");
        int m=this.userMapper.batch_delete(arr);
        System.out.println("mmmmm>>>>"+m);
        return m>=1;
    }

    @Override
    public User login(User user) {
        return this.userMapper.login(user);
    }
}
